package com.example.plat.service.impl;

import com.example.plat.enity.Activity;
import com.example.plat.mapper.TipMapper;
import com.example.plat.service.TipService;
import com.example.plat.util.TimeFormateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class TipServiceImpl implements TipService {

    @Autowired
    TipMapper mapper;

    @Autowired
    TimeFormateUtil formateUtil;

    @Override
    public List<Activity> getTip(Long userId) {
        List<Activity> list = mapper.getJoinActivity(userId);
        List<Activity> res = new ArrayList<>();
        for(Activity activity:list){
            if(formateUtil.judgeRecent(activity.getTime())){
                res.add(activity);
            }
        }
        return res;
    }

    @Override
    public Integer getRecentNum(Long userId) {
        List<Activity> list = mapper.getRecentNum(userId);
        Integer num = 0;
        for(Activity activity:list){
//            int index = activity.getTime().indexOf(',');
            if(formateUtil.judgeRecent(activity.getTime())){
                num++;
            }
        }
        return num;
    }
}
